<?php
/**
* @application Automatical Judging System
* @author deltamaster
* @copyright Softrank Research Center
* @version 2.0.0.0
*/
 
require_once "./include/common.inc.php";

if (array_key_exists('action',$_GET) && $_GET['action']=='exit')
{
	if (!$_SESSION['uid']) showmessage($lang['invalid_operation'], 'index.php');
	session_unregister('uid');
	session_unregister('username');
	session_unregister('nickname');
	session_unregister('adminid');
	showmessage($lang['logout_success'], 'index.php');
}

if ($sys_uid)
{
	showmessage($lang['relogin'], 'index.php');
}
else
{
	if (submitcheck('login'))
	{
		$inputpassword = md5($_POST['inputpassword']);
		$query = $db->query("SELECT * FROM `sj_user` WHERE `username`='{$_POST['inputusername']}' AND `password`='{$inputpassword}'");
		
		if ($db->num_rows($query))
		{
			$user = $db->fetch_array($query);
			$_SESSION['uid'] = $user['id'];
			$_SESSION['username'] = $user['username'];
			$_SESSION['adminid'] = $user['group'];
			showmessage($lang['login_success'], 'index.php');
		}
		else
		{
			showmessage($lang['login_fail'],'login.php');
		}
	}
}
include template('login');

?>